﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Service
{
    public partial class UserRegister : PageBaseService
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string email = Request["email"] ?? "";
            string username = Request["username"] ?? "";
            string password = Request["password"] ?? "";
            string secretkey=Request["secretkey"]??"";

            if (!IsValidKey(secretkey, email, username, password))
            {
                Response.Write("112");//密钥不正确 
                return;
            }


            Model.UserInfo user = new Model.UserInfo();
            if (Request["email"] != null && Request["username"] != null && Request["password"] != null)
            {
                user.Email = Request["email"].ToString();
                user.UserName = Request["username"].ToString();
                user.Password = Request["password"].ToString();

                string userID = string.Empty;
                string result = BLL.UserInfoBLL.Instance.FirstStepOfRegister(user, out userID);
                Response.Write(result);
            }
            else
            {
                Response.Write("111");
            }
        }

        private bool IsValidKey(string secretkey, string email, string username, string password)
        {
            if (secretkey_enable)
            {
                if (string.IsNullOrEmpty(secretkey))
                {
                    return false;
                }
                else
                {
                    string finalkey = base.EncryptMD5(public_key+current_day+email+username+password).Substring(6,22);
                    return secretkey == finalkey;
                }
            }
            else
            {
                return true;
            }
        }
    }
}